home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-16 | 4.1 KB | 118 lines | [TEXT/MPS ] |
- #-----------------------------------------------------------------------------------------------------------------------------------------------------
- # RevertToVersion
- # MPW Shell Script
- # Written by Gina Cherry • August 16, 1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage:
- # RevertToVersion file [version]
- #
- # Function:
- # RevertToVersion allows the user to revert to a previous version of a Projector file by copying
- # the old version of the file to a new revision. If no version is specified on the command line,
- # RevertToRevision prompts the user for a version number. It is necessary to create a new
- # revision of the file, because it is impossible to delete revisions from the top in Projector.
- # RevertToVersion also copies the comment and the task from the old version to the new version,
- # and prepends a comment that the file has reverted to a previous revision.
- #-----------------------------------------------------------------------------------------------------------------------------------------------------
-
-
- # If more than 2 parameters were given, write error message and exit script.
- If {#} > 2
- Echo "### Usage: {0} file [version]"
- Exit 1
- End >> Dev:StdErr
-
- # Don't exit on error.
- Set Exit 0
-
- # Initialize variables.
- Set revision ""
- Set file ""
-
- # Loop through parameters.
- For item in {"parameters"}
-
- # If the parameter is one or more digits followed by zero or more sequences of a letter and one or
- # more digits (i.e. a legal version number) and if the revision variable has not been set, set
- # revision to the parameter.
- If "{item}" =~ /[0-9]+([a-z][0-9]+)*/
- If {revision} == ""
- Set revision "{item}"
- # If revision has been set, write error message and exit script.
- Else
- Echo "### Usage: {0} file [version]"
- Exit 1
- End
-
- # Otherwise, if the file variable has not been set, set file to the parameter.
- Else
- If {file} == ""
- Set file "{item}"
- # If the file variable has been set, write error message and exit script.
- Else
- Echo "### Usage: {0} file [version]"
- Exit 1
- End
- End >> Dev:StdErr
- End
-
- # If no file was specified on the command line, write error message and exit script.
- If "{file}" == ""
- Echo "### {0}: Must specify a file."
- Echo "### Usage: {0} file [version]"
- Exit 1
- End >> Dev:StdErr
-
- # If no version was specified on the command line, prompt user for a version number.
- If "{revision}" == ""
- Set revision `Request "Version to which to revert:"` > Dev:Null
- # Exit if Cancel was chosen.
- Exit If {revision} == ""
- End
-
- # Check out the specified revision of the specified file. If Checkout is not successful, exit script.
- CheckOut "{file},{revision}" || Exit 2
-
- # Set info variable to the information returned by the ProjectInfo command.
- Set info "`ProjectInfo -comments "{file},{revision}"`"
-
- # Parse this information to extract the revision number, the task, and the comment. Create
- # variables to remember this information.
- If "{info}" =~ /[∂']*≈,([¬ ∂']+)®1[∂']*≈ Task: (≈)®2[ ]«5»Comment: (≈)®3/
- Set task "{®2}"
- Set comment "Reverted to revision {®1}. {®3}"
- End
-
- # Copy the contents of the old version of the projector file to a temporary file.
- Duplicate -y "{file}" {0}.temp
-
- # Checkout a write-priveleged copy of the most recent version of the specified file.
- CheckOut -m "{file}"
-
- # Compare the old version of the file with the newest version, discarding output.
- Compare -b "{file}" {0}.temp > Dev:Null
-
- # Save the return value from the Compare command.
- Set myStatus {Status}
-
- # If the 2 versions are the same, cancel the checkout.
- If {myStatus} == 0
- Echo "# Version {revision} matches the most recent version of the projector file {file}"
- # Cancel the file checkout, returning the projector database to its original state.
- Checkout -y -cancel "{file}"
-
- # If the 2 versions are different, copy the text of the old version to the new version. Close and
- # check in the file.
- Else If {myStatus} == 2
- Open {0}.temp
- Copy •:∞ {0}.temp
- Close -n {0}.temp
- Open "{file}"
- Paste •:∞ "{file}"
- Close -y "{file}"
- CheckIn "{file}" -cs "{comment}" -t "{task}"
- End
-
- # Delete the temporary file.
- Delete -y {0}.temp